<?php
/**
 * Created by PhpStorm.
 * User: xuke
 * Date: 16/6/7
 * Time: 下午4:06
 */
namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Route;
class CheckRight
{
    //这个中间间,主要是验证用户token是否合法
    public function handle($request, Closure $next, $guard = null)
    {
        $admin = Auth::guard('web')->user();

        $role = $admin->role;
        if (!$admin->isSuper()){
            if ($role->is_use == 0)
            {
                response('对不起,您的角色已经被禁用.', 401);
            }else{
                $nodes = $role->nodes;
                if (!$nodes->pluck('url')->contains($request->path()))
                {
                    return response('对不起,您没有权限操作.', 401);
                }

            }
        }

        return $next($request);
    }
}